import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Test100 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[50010];
        for(int i = 0;i<n;i++){
            arr[i] = sc.nextInt();
        }
        int[] ret = new int[n];
        int m = 0;
        int q = n;
        for(int i = 0;i<50010;i++){
            if(m < n) ret[m++] = arr[i];
            if(arr[i+1] != n){
                arr[q++] = arr[i+1];
                i++;
            }else{
                break;
            }
        }
        for(int i = 0;i<n;i++){
            System.out.print(ret[i]+" ");
        }
    }
}
